package ${filePackageName};

import ${entityPackage}.${upperEntityName};
import ${dtoPackage}.${upperEntityName}Dto;
import ${voPackage}.${upperEntityName}Vo;
import ${servicePackage}.${upperEntityName}Service;
import ${utilsPackage}.MessageConstant;
import ${utilsPackage}.MessageUtils;
import ${annotationPackage}.SysLog;
import ${beanCommonPackage}.Response;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * ${tableComment}
 * 
 * @author ${projectAuthor}
 * @version 1.0
 * @date ${nowDate}
 */
@Api(tags="${tableComment}")
@RequestMapping(value = "${accessBaseUrl}")
@RestController
public class ${upperEntityName}Controller extends BaseController{

	@Resource
	private ${upperEntityName}Service ${lowerEntityName}Service;

	/**
	 * 查询${upperEntityName}集合
	 * @param ${lowerEntityName}Dto 查询条件
	 * @return 分页集合
	 * @throws Exception 异常
	 */
	@ApiOperation(value="分页查询${tableComment}")
	@GetMapping(value = "/${lowerEntityName}s", produces = MediaType.APPLICATION_JSON_VALUE)
	public Response<List<${upperEntityName}Vo>> pageList(${upperEntityName}Dto ${lowerEntityName}Dto, HttpServletRequest request) throws Exception {
		return Response.page(${lowerEntityName}Service.selectPage(${lowerEntityName}Dto));
	}

	/**
	 * 根据${lowerPrimaryKey}查询${upperEntityName}
	 * @param ${lowerPrimaryKey} 主键ID
	 * @return 查询的对象
	 * @throws Exception 异常
	 */
	@ApiOperation(value="查询单个${tableComment}")
	@GetMapping(value = "/${lowerEntityName}/{${lowerPrimaryKey}}", produces = MediaType.APPLICATION_JSON_VALUE)
	public Response<${upperEntityName}Vo> selectById(@PathVariable ${primaryType} ${lowerPrimaryKey}, HttpServletRequest request) throws Exception {
		return Response.data(${lowerEntityName}Service.selectById(${lowerPrimaryKey}));
	}

	/**
	 * 新增${upperEntityName}
	 * @param ${lowerEntityName} ${tableComment}对象
	 * @return 消息结果
	 * @throws Exception 异常
	 */
	@ApiOperation(value="新增${tableComment}")
	@SysLog(operateType="新增${tableComment}")
	@PostMapping(value = "/${lowerEntityName}",produces = MediaType.APPLICATION_JSON_VALUE)
	public Response insert(@RequestBody ${upperEntityName} ${lowerEntityName}, HttpServletRequest request) throws Exception{
		${lowerEntityName}Service.insert(${lowerEntityName});
		return Response.data(${lowerEntityName}.get${upperPrimaryKey}(), MessageUtils.get(MessageConstant.INSERT_SUCCESS));
	}

	/**
	 * 修改${upperEntityName}
	 * @param ${lowerEntityName} ${tableComment}对象
	 * @return 消息结果
	 * @throws Exception 异常
	 */
	@ApiOperation(value="修改${tableComment}")
	@SysLog(operateType="修改${tableComment}")
	@PutMapping(value = "/${lowerEntityName}", produces = MediaType.APPLICATION_JSON_VALUE)
	public Response update(@RequestBody ${upperEntityName} ${lowerEntityName}, HttpServletRequest request) throws Exception {
		${lowerEntityName}Service.update(${lowerEntityName});
		return Response.success(MessageUtils.get(MessageConstant.MODIFY_SUCCESS));
	}

	/**
	 * 删除${upperEntityName}
	 * @param ${lowerPrimaryKey} ${primaryKeyComment}
	 * @return 消息结果
	 * @throws Exception 异常
	 */
	@ApiOperation(value="删除${tableComment}")
	@SysLog(operateType="删除${tableComment}")
	@DeleteMapping(value = "/${lowerEntityName}/{${lowerPrimaryKey}}", produces = MediaType.APPLICATION_JSON_VALUE)
	public Response deleteOne(@PathVariable ${primaryType} ${lowerPrimaryKey}, HttpServletRequest request) throws Exception{
		${lowerEntityName}Service.delete(${lowerPrimaryKey});
		return Response.success(MessageUtils.get(MessageConstant.DELETE_SUCCESS));
	}

	/**
	 * 批量删除${upperEntityName}
	 * @param ${lowerPrimaryKey}s ${primaryKeyComment}集合
	 * @return 消息结果
	 * @throws Exception 异常
	 */
	@ApiOperation(value="批量删除${tableComment}")
	@SysLog(operateType="批量删除${tableComment}")
	@DeleteMapping(value = "/${lowerEntityName}s", produces = MediaType.APPLICATION_JSON_VALUE)
	public Response deleteBatch(@RequestBody ArrayList<${primaryType}> ${lowerPrimaryKey}s, HttpServletRequest request) throws Exception{
		${lowerEntityName}Service.delete(${lowerPrimaryKey}s.toArray(new ${primaryType}[0]));
		return Response.success(MessageUtils.get(MessageConstant.DELETE_SUCCESS));
	}
}